package com.unytech.project.web.taglib;

import java.util.Iterator;
import java.util.Set;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.opensymphony.xwork2.ActionContext;
import com.unytech.project.common.Globals;
import com.unytech.project.entity.system.Permission;
import com.unytech.project.entity.system.User;

public class PermissionTag extends TagSupport{
	ActionContext cxt = ActionContext.getContext();
	private String subpermname;
	private boolean result = false;
	
	@Override
	public int doStartTag() throws JspException {
		User user = (User) cxt.getSession().get(Globals.SESSION_USERINSESSION_KEY);
		Set<Permission> perms = user.getPermgroup().getPermissions();
		Iterator<Permission> permit = perms.iterator();
		while (permit.hasNext()) {
			Permission perm = permit.next();
			if (perm.getPermname().equals(subpermname));
			result = true;
			break;
		}
		
		
		
		return result? EVAL_BODY_INCLUDE : SKIP_BODY;
	}



	public String getSubpermname() {
		return subpermname;
	}

	public void setSubpermname(String subpermname) {
		this.subpermname = subpermname;
	}

}
